#coding=utf-8
import urllib
from itertools import chain


#decode url
def urldecode(query):
    d = {}
    a = query.split('&')
    for s in a:
        if s.find('='):
            k, v = map(urllib.unquote, s.split('='))
            try:
                d[k].append(v)
            except KeyError:
                d[k] = [v]
    return d


#判断是否是数字
def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata

        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False


#迭代器，大数据不使用查询缓存
def my_iterator(queryset):
    the_iterator = queryset.iterator()

    try:
        first_result = next(the_iterator)
    except StopIteration:
        # No rows were found, so do nothing.
        return []
    else:
        return chain([first_result], the_iterator)